var t = require("../../../../@babel/runtime/helpers/interopRequireDefault"), a = t(require("../../../../@babel/runtime/regenerator")), e = require("../../../../@babel/runtime/helpers/asyncToGenerator"), i = t(require("../../../../utils/util.js")), o = require("../../../../mycomponent/payKeyboard/PayKeyboardAsync"), s = getApp();

Page({
    data: {
        showone: !1,
        showthr_Mun: "",
        in_status: 1,
        showphone: !1,
        goods_id: "",
        id: "",
        now: "",
        posterShow: !1,
        isclick: !0,
        countDownObj: {
            day: "00",
            hou: "00",
            min: "00",
            sec: "00"
        },
        password: "",
        setIntervalMth: "",
        is_last_bidder: !1,
        isEnd: !1,
        explainShow: !1,
        payKeyboardShow: !1,
        remind_msg_switch: !1,
        is_remind_msg: !1,
        member_explain: ""
    },
    onLoad: function(t) {
        if (this.setData({
            now: String(Date.parse(new Date())).substring(0, 10)
        }), t.scene) {
            var a = decodeURIComponent(t.scene);
            if (console.log(a), a) {
                var e = [];
                e = a.split(",");
                for (var i = 0; i < e.length; i++) {
                    var o;
                    "member_id" == (o = e[i].split("="))[0] && this.setData({
                        id: o[1]
                    }), "id" == o[0] && this.setData({
                        goods_id: o[1]
                    });
                }
            }
        }
        t.id && this.setData({
            goods_id: t.id
        }), t.member_id && this.setData({
            id: t.member_id
        });
    },
    is_password: function(t) {
        console.log(t.detail.value), this.setData({
            password: t.detail.value
        });
    },
    onChange: function(t) {
        this.setData({
            timeData: t.detail
        });
    },
    goto: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    gotoCart: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    gotoMY: function() {
        wx.reLaunch({
            url: "/packageG/member_v2/member_v2"
        });
    },
    showthr_del: function() {
        Number(this.data.price) <= Number(this.data.auction.mini_markup) ? wx.showToast({
            title: "出价不能低于当前价格",
            icon: "none",
            duration: 1e3
        }) : this.setData({
            price: Number(Number(this.data.price) - Number(this.data.auction.mini_markup)).toFixed(2)
        });
    },
    toRecord: function() {
        wx.navigateTo({
            url: "/packageD/auction/auction/auction_record/auction_record?id=" + this.data.goods_id
        });
    },
    showthr_add: function() {
        this.setData({
            price: Number(Number(this.data.price) + Number(this.data.auction.mini_markup)).toFixed(2)
        });
    },
    isprice: function(t) {
        console.log(t.detail.value), this.setData({
            showthr_Mun: t.detail.value
        }), console.log(this.data.showthr_Mun);
    },
    isCoverLayer_passwork: function() {
        wx.showModal({
            title: "提示",
            content: "不输入店铺密码无法查看拍品详情",
            success: function(t) {
                t.confirm ? (console.log("用户点击确定"), wx.navigateBack({
                    delta: 1
                })) : t.cancel && console.log("用户点击取消");
            }
        });
    },
    confirm: function() {
        var t = {
            art: "verifyPassword",
            auction_id: this.data.id,
            passwd: this.data.password
        }, a = this, e = s.getNetAddresss("plugin.auction.api.index.getAuctionData");
        s._getNetWork({
            url: e,
            data: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    showone: !1
                }), a.getStatus()) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    isCoverLayer: function() {
        this.setData({
            showtwo: !1,
            showthr: !1,
            showphone: !1,
            explainShow: !1
        });
    },
    celquxiao: function() {
        this.setData({
            showtwo: !1,
            showphone: !1
        });
    },
    gotoPay: function() {
        console.log("去支付");
    },
    goMybtn: function() {
        wx.navigateTo({
            url: "/packageD/auction/auction-mine/my_index/my_index"
        });
    },
    gomyshop: function(t) {
        wx.navigateTo({
            url: "/packageD/auction/auctioneer-shop/auctioneer_shop/auctioneer_shop?id=" + this.data.id
        });
    },
    saveImg: function() {
        wx.previewImage({
            current: "this.data.posterImg.image_url",
            urls: [ this.data.posterImg.image_url ]
        });
    },
    bid: function() {
        console.log(0 == this.data.auction.is_prepay), 0 == this.data.invite_mobile ? wx.navigateTo({
            url: "/packageA/member/editmobile/editmobile"
        }) : 0 == this.data.auction.is_prepay ? this.setData({
            explainShow: !0
        }) : this.setData({
            showthr: !0
        });
    },
    explainPayTap: function() {
        wx.showToast({
            duration: 1e3,
            title: "需先支付".concat(this.data.auction.prepayment, "保证金方可出价"),
            icon: "none"
        }), this.getPayData();
    },
    getPayData: function() {
        this.actionSheetItems = [];
        var t = {
            goods_id: this.data.goods_id
        }, a = this, e = s.getNetAddresss("plugin.auction.api.prepayment.page");
        s._getNetWork({
            url: e,
            data: t,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var i = e.data.buttons;
                    a.setData({
                        btnData: i,
                        rewardPayshow: !0
                    }), a.getData();
                } else wx.showToast({
                    title: res.msg,
                    icon: "none",
                    duration: 1e3
                }), wx.hideLoading();
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    payKeyboardComplete: function(t) {
        o.payKeyboardAsync.complete(t.detail);
    },
    getPayKeyboardPassword: function() {
        return this.setData({
            payKeyboardShow: !0
        }), new Promise(function(t, a) {
            o.payKeyboardAsync.addCompleteFn(function(a) {
                t(a);
            });
        });
    },
    payBtn: function(t) {
        var i = this;
        return e(a.default.mark(function e() {
            var o, n, r, d, c;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    if (3 != (o = t.currentTarget.dataset.value) || i.data.isclick) {
                        a.next = 4;
                        break;
                    }
                    return wx.showToast({
                        title: "余额不能重复支付",
                        icon: "none",
                        duration: 1e3
                    }), a.abrupt("return");

                  case 4:
                    if (n = {
                        money: Number(i.data.auction.prepayment),
                        goods_id: Number(i.data.goods_id),
                        pay_way: Number(o)
                    }, console.log(i.data.need_password, o), !i.data.need_password || 3 != o) {
                        a.next = 11;
                        break;
                    }
                    return a.next = 9, i.getPayKeyboardPassword();

                  case 9:
                    r = a.sent, n.password = r;

                  case 11:
                    wx.showLoading({
                        title: "支付中",
                        duration: 1e3,
                        icon: "none"
                    }), d = {}, c = s.getNetAddresss("plugin.auction.api.prepayment.recharge"), s._getNetWork({
                        url: c,
                        data: n,
                        success: function(t) {
                            var a = t.data;
                            if (i.setData({
                                rewardPayshow: !1
                            }), 1 == a.result) {
                                switch (o) {
                                  case 1:
                                  case 55:
                                    d = {
                                        timeStamp: a.data.config.timestamp,
                                        nonceStr: a.data.config.nonceStr,
                                        package: a.data.config.package,
                                        signType: a.data.config.signType,
                                        paySign: a.data.config.paySign
                                    }, console.log("ssssss"), i.WXPay(d);
                                    break;

                                  case 3:
                                    i.data.isclick && (i.setData({
                                        rewardPayshow: !1,
                                        isclick: !1,
                                        explainShow: !1,
                                        showthr: !0
                                    }), i.getData());
                                }
                                wx.hideLoading();
                            } else wx.hideLoading(), wx.showToast({
                                title: a.msg,
                                icon: "none",
                                duration: 2e3
                            });
                        },
                        fail: function(t) {
                            console.log(t);
                        }
                    });

                  case 15:
                  case "end":
                    return a.stop();
                }
            }, e);
        }))();
    },
    WXPay: function(t) {
        var a = this, e = s.getNetAddresss("order.mini-app.index");
        wx.requestPayment({
            timeStamp: t.timeStamp,
            nonceStr: t.nonceStr,
            package: t.package,
            signType: t.signType ? t.signType : "MD5",
            paySign: t.paySign,
            success: function(i) {
                var o = {
                    formID: t.package.slice(10),
                    orderId: a.data.order_id
                };
                s._postNetWork({
                    url: e,
                    showToastIn: !1,
                    data: o,
                    success: function(t) {
                        var e = t.data;
                        0 == e.result ? wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        }) : (wx.showToast({
                            title: "支付成功"
                        }), a.setData({
                            rewardPayshow: !1,
                            explainShow: !1,
                            showthr: !0
                        }), a.getData());
                    },
                    fail: function(t) {}
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: "支付失败请稍后重试",
                    icon: "none",
                    duration: 2e3,
                    success: function() {},
                    fail: function() {}
                });
            }
        });
    },
    _timeCompare: function(t) {
        var a = new Date(1e3 * parseInt(t));
        new Date() >= a ? (this.setData({
            isTime: !0
        }), this._countDown()) : (this.setData({
            isTime: !1,
            isBegTime: !0,
            begTimeStr: 1e3 * t
        }), this.beginDown());
    },
    _countDown: function() {
        var t = new Date().getTime(), a = this.data.endTime, e = null;
        if (a - t > 0) {
            var i = (a - t) / 1e3, o = parseInt(i / 86400), s = parseInt(i % 86400 / 3600), n = parseInt(i % 86400 % 3600 / 60), r = parseInt(i % 86400 % 3600 % 60);
            e = {
                day: this._timeFormat(o),
                hou: this._timeFormat(s),
                min: this._timeFormat(n),
                sec: this._timeFormat(r)
            };
        } else e = {
            day: "00",
            hou: "00",
            min: "00",
            sec: "00"
        };
        this.setData({
            countDownObj: e
        }), a - t < 0 ? this.setData({
            countDownObj: {
                day: "00",
                hou: "00",
                min: "00",
                sec: "00"
            }
        }) : setTimeout(this._countDown.bind(this), 1e3);
    },
    beginDown: function() {
        var t = new Date().getTime(), a = this.data.begTimeStr, e = null;
        if (a - t > 0) {
            var i = (a - t) / 1e3, o = parseInt(i / 86400), s = parseInt(i % 86400 / 3600), n = parseInt(i % 86400 % 3600 / 60), r = parseInt(i % 86400 % 3600 % 60);
            e = {
                day: this._timeFormat(o),
                hou: this._timeFormat(s),
                min: this._timeFormat(n),
                sec: this._timeFormat(r)
            };
        } else this.setData({
            isTime: !0,
            isBegTime: !1
        }), e = {
            day: "00",
            hou: "00",
            min: "00",
            sec: "00"
        };
        this.setData({
            beginDownObj: e
        }), a - t < 0 ? (this.setData({
            isTime: !0,
            isBegTime: !1
        }), this.setData({
            beginDownObj: {
                day: "00",
                hou: "00",
                min: "00",
                sec: "00"
            }
        })) : setTimeout(this.beginDown.bind(this), 1e3);
    },
    _timeFormat: function(t) {
        return t < 10 ? "0" + t : t;
    },
    toBuy: function(t) {
        wx.navigateTo({
            url: "/packageD/buy/myOrder_v2/myOrder_v2?goodsId=" + this.data.goods_id + "&tag=auction&total=1&auction_sn=" + this.data.auction.acution_sn + "&fixed_price=1"
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getStatus();
    },
    onHide: function() {
        this.data.setIntervalMth = null, clearInterval(this.data.setIntervalMth), console.log("dddddddddddddddd222222222222", this.data.setIntervalMth);
    },
    onUnload: function() {
        this.data.setIntervalMth = null, clearInterval(this.data.setIntervalMth), console.log("dddddddddddddddd222222222222", this.data.setIntervalMth);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    bidTo: function() {
        var t = {
            goods_id: Number(this.data.goods_id),
            price: Number(this.data.price)
        }, a = this, e = s.getNetAddresss("plugin.auction.api.bid.bid");
        s._getNetWork({
            url: e,
            data: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? wx.showToast({
                    title: e.msg,
                    duration: 1e3,
                    icon: "none",
                    success: function() {
                        setTimeout(function() {
                            a.setData({
                                showthr: !1
                            }), a.getData();
                        }, 500);
                    }
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    posterimgTap: function() {
        this.setData({
            posterShow: !0
        }), this.postShow();
    },
    posterClose: function() {
        this.setData({
            posterShow: !1
        });
    },
    posterClose_reward: function() {
        this.setData({
            rewardPayshow: !1
        });
    },
    postShow: function() {
        wx.showLoading({
            title: "海报生成中"
        });
        var t = {
            id: this.data.goods_id
        }, a = this, e = s.getNetAddresss("plugin.auction.api.goodsPoster.generateGoodsPoster");
        s._getNetWork({
            url: e,
            data: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    posterImg: e.data
                }), wx.hideLoading()) : (wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                }), wx.hideLoading());
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    toCollect: function() {
        var t = {
            art: "collectionShop",
            auctioneer_id: this.data.id
        }, a = this, e = s.getNetAddresss("plugin.auction.api.index.getAuctionData");
        s._getNetWork({
            url: e,
            data: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.getData() : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getStatus: function() {
        var t = this, a = this, e = s.getNetAddresss("plugin.auction.api.index.getAuctionData"), i = {
            member_id: a.data.id
        };
        s._postNetWork({
            url: e,
            data: i,
            success: function(e) {
                var i = e.data;
                1 == i.result ? (console.log(i), a.setData({
                    status: i.data.getVerify.status,
                    is_verify: i.data.getVerify.is_verify
                }), 0 == a.data.is_verify && 1 == a.data.status ? a.setData({
                    showone: !0
                }) : (a.setData({
                    is_verify: 1
                }), a.getData(), t.data.isEnd || (a.data.setIntervalMth = setInterval(function() {
                    console.log("进入倒计时"), a.getNewest();
                }, 5e3)), a.getInvite())) : wx.showToast({
                    title: i.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getNewest: function() {
        var t = this, a = s.getNetAddresss("plugin.auction.api.index.newest");
        s._postNetWork({
            url: a,
            data: {
                goods_id: this.data.goods_id
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    record: e.data.auction.record.data.splice(0, 5),
                    record_length: e.data.auction.record.total,
                    "auction.is_prepay": e.data.auction.is_prepay,
                    "auction.start_shooting": e.data.auction.start_shooting,
                    "auction.end_shooting": e.data.auction.end_shooting,
                    price: Number(t.data.price) > Number(e.data.auction.price) ? t.data.price : Number(e.data.auction.price).toFixed(2)
                }), e.data.auction.last_bidder && "-1" == e.data.auction.auc_status && wx.showModal({
                    content: "您是本场出价最高者，3分钟后自动生成订单，请到我的—待确认栏目里确认订单。",
                    duration: 1500,
                    showCancel: !1
                }), "-1" == e.data.auction.auc_status && (t.setData({
                    isEnd: !0
                }), t.data.setIntervalMth = null, clearInterval(t.data.setIntervalMth))) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getInvite: function() {
        var t = this, a = s.getNetAddresss("member.member.isValidatePage");
        s._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    invite_mobile: e.data.invite_mobile
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    finished: function(t) {
        this.getData();
    },
    finished_start: function(t) {
        this.setData({
            now: String(Date.parse(new Date())).substring(0, 10)
        }), this.getData(!1, "start");
    },
    getData: function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] && arguments[0], a = this, e = s.getNetAddresss("plugin.auction.api.index.getAuctionData"), o = {
            member_id: a.data.id,
            goods_id: a.data.goods_id,
            art: "goodsDetail"
        };
        s._postNetWork({
            url: e,
            data: o,
            success: function(e) {
                var o = e.data;
                1 == o.result ? (a.setData({
                    now: String(Date.parse(new Date())).substring(0, 10),
                    auction: o.data.goodsDetail.auction,
                    price: Number(a.data.price) > Number(o.data.goodsDetail.auction.now_price) ? a.data.price : Number(o.data.goodsDetail.auction.now_price).toFixed(2),
                    startTime: i.default.formatTimeTwo(o.data.goodsDetail.auction.start_shooting, "Y-M-D h:m:s"),
                    endTime: i.default.formatTimeTwo(o.data.goodsDetail.auction.end_shooting, "Y-M-D h:m:s"),
                    record: o.data.goodsDetail.auction.bid_record.data.splice(0, 5),
                    record_length: o.data.goodsDetail.auction.bid_record.total,
                    recharge_explain: o.data.recharge_explain,
                    need_password: o.data.need_password,
                    remind_msg_switch: o.data.goodsDetail.auction.remind_msg_switch,
                    member_explain: o.data.goodsDetail.auction.member_explain,
                    is_remind_msg: o.data.goodsDetail.auction.is_remind_msg,
                    alias: o.data.goodsDetail.auction.alias
                }), o.data.goodsDetail.auction && "-1" == o.data.goodsDetail.auction.auc_status && (clearInterval(a.data.setIntervalMth), 
                a.setData({
                    isEnd: !0
                })), o.data.goodsDetail.auction.bid_record && o.data.goodsDetail.auction.bid_record.is_last_bidder && a.setData({
                    is_last_bidder: o.data.goodsDetail.auction.bid_record.is_last_bidder
                }), t || a.setData({
                    auctioneer: o.data.goodsDetail.auctioneer
                }), a._timeCompare(a.data.auction.end_shooting), a._timeCompare(a.data.auction.start_shooting)) : wx.showToast({
                    title: o.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    msgTap: function() {
        var t = this, a = this.data.is_remind_msg ? 0 : 1, e = s.getNetAddresss("plugin.auction.api.auction.remind-msg");
        s._getNetWork({
            url: e,
            data: {
                status: a,
                goods_id: this.data.goods_id
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.getData(), wx.showModal({
                    content: e.msg,
                    showCancel: !1
                })) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});